package com.briup.bookstore.service.impl;

import com.briup.bookstore.mapper.CollectMapper;
import com.briup.bookstore.po.ext.CollectExtend;
import com.briup.bookstore.service.CollectService;
import com.briup.bookstore.utils.BeanCopyUtils;
import com.briup.bookstore.vo.CollectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author briup-adam
 * @Date 2023/7/26 上午9:09
 * @Description
 **/
@Service
public class CollectServiceImpl implements CollectService {
    @Autowired
    private CollectMapper collectMapper;

    @Override
    public List<CollectVO> findCollects(Integer userId) {
        List<CollectExtend> list = collectMapper.findCollectByUserId(userId);
        List<CollectVO> vos = BeanCopyUtils.copyBeanList(list, CollectVO.class);
        return vos;
    }

    @Override
    public void addCollect(Integer userId, Integer bookId) {
        collectMapper.save(userId, bookId);

    }

    @Override
    public void deleteCollect(Integer ... ids) {
        for (Integer id : ids) {
            collectMapper.deleteById(id);
        }

    }
}
